﻿using System.Collections.Generic;
using System.Linq;

namespace Omu.Awesome.Mvc
{
    public static class AwesomeTools
    {
        public static string MakeId(string s, string prefix = null)
        {
            if (s == null) return null;
            return (prefix ?? string.Empty) + s.Replace('.', '_').Replace('[', '_').Replace(']', '_');
        }

        public static string JsEncode(string s)
        {
            return s.Replace("\'", "\\'").Replace("\"", "\\\"");
        }

        public static string MakeIdJsArray(IEnumerable<string> arr)
        {
            return string.Join(",", arr.Select(o => "'" + MakeId(o) + "'"));
        }

        public static string MakeJsArray(IEnumerable<string> arr)
        {
            return string.Join(",", arr.Select(o => "'" + o + "'"));
        }
    }
}